package com.music.controller;

import com.alipay.api.AlipayApiException;
import com.music.dto.Result;
import com.music.entity.AlipayBean;
import com.music.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 名一
 * @ClassName OrderController
 * @description: TODO
 * @datetime 2022年 07月 11日 18:10
 * @version: 1.0
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private PayService payService;

    /**
     * 传入商户订单号 outTradeNo  订单名称 subject     付款金额 totalAmount    商品描述，可空   body
     * @param outTradeNo
     * @param subject
     * @param totalAmount
     * @param body
     * @return
     * @throws AlipayApiException
     */
    @RequestMapping(value = "alipay")
    public String alipay(@RequestParam String outTradeNo, @RequestParam String subject, @RequestParam String totalAmount, String body) throws AlipayApiException {
        AlipayBean alipayBean = new AlipayBean();
        alipayBean.setOut_trade_no(outTradeNo);
        alipayBean.setSubject(subject);
        alipayBean.setTotal_amount(totalAmount);
        alipayBean.setBody(body);
        return payService.aliPay(alipayBean);
    }

    //支付成功支付宝调用方法：
    @RequestMapping(value = "ok")
    public void ok(){
        System.out.println("付款成功！");
    }
}
